package cqut.wys.config;

import org.apache.kafka.clients.producer.KafkaProducer;
import org.apache.kafka.clients.producer.Producer;

import java.util.Properties;

/**
 * --------神兽出没--------/
 *   ┌─┐     ┌─┐
 * ┌─┘─┴─────┘─┴─┐
 * │      ─      │
 * │  ┬─┘   └─┬  │
 * │             │
 * │      ┴      │  Code is far away from bug with the animal protecting
 * └───┐      ┌──┘  神兽保佑,代码无bug
 *     │      │
 *     │      └──────┐
 *     │             ├┐
 *     │             ┌┘
 *     └┐ ┐ ┌───┬─┐ ┌┘
 *      │ ┤ ┤   │ ┤ ┤
 *      └─┴─┘   └─┴─┘
 * --------感觉萌萌哒--------/
 *
 * @author wuyoushan
 * @date 2018/7/8
 */
public class KafkaProducerConfig {

    private String keySerializer;

    private String valueSerializer;

    private String clientId;

    private String brokerList;

    public KafkaProducerConfig setKeySerializer(String keySerializer) {
        this.keySerializer = keySerializer;
        return this;
    }

    public KafkaProducerConfig setValueSerializer(String valueSerializer) {
        this.valueSerializer = valueSerializer;
        return this;
    }

    public KafkaProducerConfig setClientId(String clientId) {
        this.clientId = clientId;
        return this;
    }

    public KafkaProducerConfig setBrokerList(String brokerList) {
        this.brokerList = brokerList;
        return this;
    }

    public Producer buildProducer() {
        Properties properties = new Properties();
        properties.put("key.serializer", keySerializer);
        properties.put("value.serializer", valueSerializer);
        properties.put("client.id", clientId);
        properties.put("bootstrap.servers", brokerList);

        return  new KafkaProducer<>(properties);
    }
}
